﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using QLST_BUS;
using System.Data.SqlClient;


namespace QLST_CoopMart_GoVap
{
    public partial class uc_QuanLySanPham : UserControl
    {
        //DataProvider dap = new DataProvider();
        private BindingSource bdSource = new BindingSource();
        public uc_QuanLySanPham()
        {
            InitializeComponent();
        }

        private void uc_QuanLySanPham_Load(object sender, EventArgs e)
        {
            SqlParameter[] parameters = new SqlParameter[1];
            parameters[0] = new SqlParameter("@MaLoai", 1);
          //  bdSource.DataSource = dap.ExcuteProcedureGetTable("st_GetHangHoa", parameters);
            bdNavigation.BindingSource = bdSource;
            dgvSanPham.DataSource = bdSource;

            //
            //CanhBaoHetHang();
           
        }

        private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
        
          
        
        }

        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            frmThem_CapNhatHangHoacs frm = new frmThem_CapNhatHangHoacs();
            frm.ShowDialog();
        }

        private void dgvSanPham_DataSourceChanged(object sender, EventArgs e)
        {
          
          //  MessageBox.Show(dgvSanPham.Rows[0].Cells[1].Value.ToString());
        }

        public void CanhBaoHetHang()
        {
            //Duyệt lại
            int DinhMucTon = 0;
            int SoLuong;
            foreach (DataGridViewRow dr in dgvSanPham.Rows)
            {
                DinhMucTon = int.Parse(dr.Cells["DinhMucTon"].Value.ToString());
                SoLuong = int.Parse(dr.Cells["SoLuong"].Value.ToString());
                if (SoLuong <= DinhMucTon)
                {
                    dr.DefaultCellStyle.ForeColor = Color.Red;

                }
            }
          
        }

        private void dgvSanPham_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            
           
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            CanhBaoHetHang();

            ////Duyệt lại
            //int DinhMucTon = 0;
            //foreach (DataGridViewRow dr in dgvSanPham.Rows)
            //{
            //    DinhMucTon = int.Parse(dr.Cells["DinhMucTon"].Value.ToString());
            //    if (DinhMucTon < 2)
            //    {
            //        dr.DefaultCellStyle.ForeColor = Color.Red;

            //    }
            //}
        }

        private void dgvSanPham_DataMemberChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click_2(object sender, EventArgs e)
        {
            CanhBaoHetHang();
        }
    }
}
